const Mock = require('mockjs')

const data = Mock.mock({
    'users|30': [{
        id: '@increment',
        phone: '13725494967',
        userName: '@name',
        realName: '@cname',
        sex: '@string("男女", 1, 1)',
        email: '@email',
        address: '@county(true)'
    }]
})

// var obj = {
//     code: 2000,
//     data: data.users
// }

// console.log(obj);



function searchUserByUserName(userName) {
    var searchRes = []
    data.users.forEach(element => {
        if (element.userName == userName) {
            searchRes.push(element)
        }
    });
    return searchRes;
}


module.exports = [
    //getAllUser 
    {
        url: '/admin/getAllUser',
        type: 'get',
        response: config => {
            return {
                code: 20000,
                data: data.users
            }
        }
    },
    {
        url: '/admin/delUserById',
        type: 'post',
        response: config => {
            let { id } = config.query
            console.log(id);
            return {
                code: 20000,
                data: "success"
            }
        }
    },
    {
        url: '/admin/searchUserByUserName',
        type: 'post',
        response: config => {
            let { userName } = config.query
            console.log(userName);
            return {
                code: 20000,
                data: searchUserByUserName(userName)
            }
        }
    }
]